package com.jawmask.android.stuartproair.ui.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.LinearLayout;

import com.jawmask.android.stuartproair.R;

public class GNBView extends LinearLayout {

	public static final int SERVICE_MENU = 0;
	public static final int REMAINDER_MENU = 1;
	public static final int CONTACT_MENU = 2;
	public static final int SOCIAL_MENU = 3;
	public static final int SPECIALS_MENU = 4;

	private OnGNBCliked onGNBClikedListener = null;

	public interface OnGNBCliked {
		public void onGNBCliked(int value);
	}

	private CheckedTextView serviceMenu, remainderMenu, contactMenu, socialMenu, specialsMenu;

	public GNBView(Context context) {
		super(context);
		customInflate();
	}

	public GNBView(Context context, AttributeSet attrs) {
		super(context, attrs);
		customInflate();
	}

	private void customInflate() {
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.action_bars, this);

		serviceMenu = (CheckedTextView) findViewById(R.id.service_menu);
		serviceMenu.setOnClickListener(listener);

		remainderMenu = (CheckedTextView) findViewById(R.id.remainder_menu);
		remainderMenu.setOnClickListener(listener);

		contactMenu = (CheckedTextView) findViewById(R.id.contact_menu);
		contactMenu.setOnClickListener(listener);

		socialMenu = (CheckedTextView) findViewById(R.id.social_menu);
		socialMenu.setOnClickListener(listener);

		specialsMenu = (CheckedTextView) findViewById(R.id.specials_menu);
		specialsMenu.setOnClickListener(listener);
	}

	public void setCurrentGNB(int value) {
		switch (value) {
		case SERVICE_MENU:
			serviceMenu.setChecked(true);
			remainderMenu.setChecked(false);
			contactMenu.setChecked(false);
			socialMenu.setChecked(false);
			specialsMenu.setChecked(false);
			break;
		case REMAINDER_MENU:
			remainderMenu.setChecked(true);
			serviceMenu.setChecked(false);
			contactMenu.setChecked(false);
			socialMenu.setChecked(false);
			specialsMenu.setChecked(false);
			break;
		case CONTACT_MENU:
			contactMenu.setChecked(true);
			remainderMenu.setChecked(false);
			serviceMenu.setChecked(false);
			socialMenu.setChecked(false);
			specialsMenu.setChecked(false);
			break;
		case SOCIAL_MENU:
			socialMenu.setChecked(true);
			contactMenu.setChecked(false);
			remainderMenu.setChecked(false);
			serviceMenu.setChecked(false);
			specialsMenu.setChecked(false);
			break;
		case SPECIALS_MENU:
			specialsMenu.setChecked(true);
			socialMenu.setChecked(false);
			contactMenu.setChecked(false);
			remainderMenu.setChecked(false);
			serviceMenu.setChecked(false);
			break;
		}
	}

	private OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.service_menu:
				if (onGNBClikedListener != null)
					onGNBClikedListener.onGNBCliked(SERVICE_MENU);
				break;
			case R.id.remainder_menu:
				if (onGNBClikedListener != null)
					onGNBClikedListener.onGNBCliked(REMAINDER_MENU);
				break;
			case R.id.contact_menu:
				if (onGNBClikedListener != null)
					onGNBClikedListener.onGNBCliked(CONTACT_MENU);
				break;
			case R.id.social_menu:
				if (onGNBClikedListener != null)
					onGNBClikedListener.onGNBCliked(SOCIAL_MENU);
				break;
			case R.id.specials_menu:
				if (onGNBClikedListener != null)
					onGNBClikedListener.onGNBCliked(SPECIALS_MENU);
				break;
			}
		}
	};

	public void setOnGNBClicked(OnGNBCliked listener) {
		onGNBClikedListener = listener;
	}
}